// 商品管理脚本
$(function() {
     $("#category").combobox({
				width :100,
				panelHeight : 100,
				editable:false 
				
			});
	$("#searchid").linkbutton({
				text : '查询',
				iconCls : 'icon-search'
			});
	$('#messagegrid').datagrid({
		title : '您所在的位置：行业/市场管理模块&nbsp;&nbsp;--&gt;&gt;&nbsp;&nbsp;产品种类',
		idField : 'id',
		width : 1000,
		height : 400,
		nowrap : false,
		striped : true,
		collapsible : false,
		url : '../type/type_search.shtml',
		frozenColumns : [[{
					field : 'ck',
					title : '选择',
					checkbox : true
				}]],
		columns : [[{
					title : '基本信息',
					colspan : 2
				}, {
					field : 'opt',
					title : '操作',
					width : 160,
					align : 'center',
					rowspan : 2,
					formatter : function(value, rec) {
					if (rec.id == undefined)
							return null;
						else
							return '<span style="color:red"><span onclick=onmodify("'
									+ rec.id
									+ '")><font style="cursor:pointer;color:blue;">修改</font></span><span onclick=ondelete("'
									+ rec.id + '")><font style="cursor:pointer;color:blue;">&nbsp;&nbsp;&nbsp;&nbsp;删除</font></span>'
									+ '<a href="javascript:viewChildrenInfo(\''+rec.id+'\')">&nbsp;&nbsp;&nbsp;&nbsp;<font style="cursor:pointer;color:blue;">查看关联信息</font></a>'
									+'</span>';
					}
				}], [{
					field : 'name',
					title : '类别名称',
					mapping : 'name',
					align : 'center',
					width : 162
				},{
					field : 'code',
					title : '类别序号',
					mapping : 'code',
					align : 'center',
					width : 162
				}

		]],
		pagination : true,
		rownumbers : true,
		queryParams : {
			name : '',
			auditingState : '-1',
			category:'-1',
			price1:'-1',
			price2:'-1',
			discode:'-1'
		},
		toolbar : [{
					id : 'btnadd',
					text : '发布信息',
					iconCls : 'icon-add',
					handler : function() {
						$(this).attr("href", '../type/type_addTypePage.shtml?menuCls=36');
					}
				}, '-'/*, {
					id : 'btnsave',
					text : '删除信息',
					iconCls : 'icon-remove',
					handler : function() {
						var records = $('#messagegrid')
								.datagrid("getSelections");
						var ids = '';
						if (null == records || records == "") {
							alert('请选择要删除的记录');
							return;
						}
						for (var i = 0; i < records.length; i++) {
							if (records[i].id == undefined
									|| records[i].id == "undefined") {

								alert('此条记录已不存在');
								return;
							}
							ids += records[i].id;
							ids += '_';
						}
						var url1 = "../type/type_deleteType.shtml";
						$.ajax({
									url : url1,
									data : "idString=" + ids,
									success : function(msg) {
										var obj = eval('(' + msg + ')');
										var result = obj[0]["message"];
										alert(result);
										$('#messagegrid').datagrid("reload");
									}
								});

					}
				}*/,{
					id : 'btnclose',
					text : ' &nbsp;关  闭',
					iconCls : 'icon-cancel',
					handler : function() {
						window.self.close();
					}
				}]
		}
	);
	 $(".searchcenter").keydown(function(){
	     if(event.keyCode==13)
         {
           onSearch();
         }
	    });
});

function onSearch() {
    //var category= $("#category").combobox("getValue");
	var queryParams = $('#messagegrid').datagrid("options").queryParams;
	queryParams.name = $("#name").val();
	queryParams.categoryId=$("#categoryId").val();
	$('#messagegrid').datagrid("reload");
}

function ondelete(id) {
	if (id == "undefined") {
		alert("此条记录已删除");
		return;
	}
	if (confirm("确定删除此条信息吗?")) {
		var url1 = "../type/type_deleteType.shtml";
		$.ajax({
				url : url1,
				data : "id=" + id,
				success : function(msg) {
					var obj = eval('(' + msg + ')');
					var result = obj[0]["message"];
					alert(result);
					$('#messagegrid').datagrid("reload");
				}
			});
	}
}
function onmodify(id) {
	if (id == "undefined") {
		alert("此条记录已被删除");
		return;
	}
	window.location.href = "../type/type_searchById.shtml?menuCls=36&id=" + id;
}
 function bigCategoryChange(){
	var bigCategoryValue = $("#bigCategory option:selected").val();
	if(bigCategoryValue != ""){
		$('#smallCategory').html('加载中... ...');
		$.get('../category/category_loadCategoryByPid.shtml?id='+bigCategoryValue+'&t='+new Date().getTime().toString(36),function(mes){
			var json = eval('('+mes+')');
			var str = '<select name="tgAnnouncement.categoryId" id="categoryId" ><option value="">请选择</option>';
			for(var i = 0; i < json.length; i++){
				str += '<option value="'+json[i]['id']+'">'+json[i]['name']+'</option>';
			}
			str+='</select>';
			$('#smallCategory').html(str);
		})
	}
}
function viewChildrenInfo(id) {
	if (id == "undefined") {
		alert("此条记录已删除");
		return;
	}
	var categoryId = $("#categoryId").val()=='0'?'':$("#categoryId").val();
	window.location.href = "../type/category_childrenInfo.jsp?menuCls=31&typeId=" + id+'&categoryId='+categoryId;
}
